<!--更改密码-->
<html>
<head>
    <meta charset="utf-8">
    <title>更改密码</title>
    <style>
        body{
            background-color: rgb(240,242,245);
        }
        #admin *{
            color: #333;
        }
    </style>

</head>
<body>
<div id="msg" style="position: relative;top: 15%">
    <div class="alert alert-dismissable">
        &nbsp;
    </div>
</div>
<div class="col-xs-6 col-md-offset-3" style="position: relative;top: 25%">
    <div class="panel panel-primary " >
        <div class="panel-heading">
            <h3 class="panel-title">密码修改</h3>
        </div>
        <div class="panel-body">
            <form class="form-inline"  id="repasswd" >
                <div class="input-group">
                    <input type="password" id="oldPasswd" name="oldPasswd" placeholder="输入旧密码" class="form-control">
                    <input type="password" id="newPasswd" name="newPasswd" placeholder="输入新密码" class="form-control">
                    <input type="password" id="reNewPasswd" name="reNewPasswd" placeholder="再次输入新密码" class="form-control">
                    <em id="tishi" style="color: red"></em>
                    <br/>
                    <span>
                        <input type="submit" value="点击修改" class="btn btn-default" name="submit">
                    </span>
                </div>
            </form>
        </div>
    </div>
</div>

    <script>
        var admin_id;
        $(function () {
            $.post("admin/getAdmin",function (data) {
                admin_id = data.obj;
            },"json");
        });
        function mySubmit(flag){
            return flag;
        }

        $(document).keyup(function () {
            if($("#newPasswd").val()!="" && $("#reNewPasswd").val()!="" && $("#newPasswd").val().length == $("#reNewPasswd").val().length && $("#newPasswd").val()!=$("#reNewPasswd").val()){
                $("#tishi").text("两次输入的新密码不同，请检查");
            }
            else {
                $("#tishi").text("");
            }
        })

        $("#repasswd").submit(function () {
            if($("#oldPasswd").val()==''||$("#newPasswd").val()==''||$("#reNewPasswd").val()==''){
                $("#tishi").text("请填写完毕后提交");
                return mySubmit(false);
            }
            else if($("#newPasswd").val()!=$("#reNewPasswd").val()){
                $("#tishi").text("两次输入的新密码不同，请检查");
                return mySubmit(false);
            }
            msg();
            return false;
        });
        function msg(){
            //tdx
            //修改管理员密码
            $.post("admin/modifyPass", {
                id: admin_id,
                oldPass: $("#oldPasswd").val(),
                newPass: $("#newPasswd").val()
            }, function(data){
                switch (data.code){
                    case 0:
                        $(".alert").removeClass("alert-success");
                        $(".alert").addClass("alert-danger");
                        $(".alert").html("<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>"+data.message);
                        break;
                    case 1:
                        location.href="index.html";
                        break;
                }
            },"json");
        }
    </script>

</body>
</html>
